<template>
    <div class="gameTable">
        <TbHeader></TbHeader>
        <gameContent></gameContent>
    </div>
    
</template>

 
<script>
import TbHeader from "@/components/gameTable/TbHeader.vue"
import gameContent from "@/components/gameTable/gameContent.vue"

export default {
    name:"gameTable",
    components:{
        TbHeader,
        gameContent
       
       
    },
    data(){
        return {
            wroker: null, //worker计算线程
            tableShow: false, //控制列表显示关闭
        }
    },
    computed: {
     table() {
      return this.$store.getters.table.length;
    },    
    loadingStore() {
      return this.$store.getters.loading;
    },
    index() {
      return this.$store.getters.index - 1;
    }
  },
  watch: {
    loadingStore: function(val, old) {
      if (val != old) {
        if (val >= 100) {
          let UId = this.$store.getters.userMsg.UId;
          let RandCode = this.$store.getters.userMsg.RandCode;
          let msg = JSON.stringify({
            ActType: 3,
            ConnectionId: "",
            Content: { HallNumber: 1 },
            ErrorCode: 10000,
            RandCode,
            UId,
            GT: 1
          });
          window.Socket.uSend(msg);
        }
      }
    },
    wroker: function(val, old) {
      if (old === null) {
        setTimeout(() => {
          this.tableShow = true;
        }, 1000);
      }
    } 
  },
  methods: {
    tabGame(x) {
      this.$store.commit("initTbale"); //初始化列表数据
      let UId = this.$store.getters.userMsg.UId;
      let RandCode = this.$store.getters.userMsg.RandCode;
      let HallNumber = x.hallnum;
      let GT = x.GT;
      let msg = JSON.stringify({
        ActType: 3,
        ConnectionId: "",
        Content: { HallNumber },
        ErrorCode: 10000,
        RandCode,
        UId,
        GT
      });
      window.Socket.uSend(msg);
      this.$store.commit("steHallIndex", x.hallnum);
    },
    postMessage(msg) {
      this.wroker.postMessage(msg);
    }
  },
//   beforeRouteEnter (to, from, next) {
//     next(vm=>{
//       // console.log(vm.listens)
//       // let i;
//       // if(window.auido.isIOS()){
//       //   for(i in vm.listens){
//       //     vm.listens[i]=window.auido.IosPlay([i]);
//       //     window.addEventListener('touchstart', vm.listens[i],false);
//       //   }
//       // }
//     })
//   },
//   创建前钩子


//   beforeCreate() {
//     if (
//       !sessionStorage.getItem("uid") ||
//       !sessionStorage.getItem("RandCode") ||
//       !sessionStorage.getItem("socketUrl") ||
//       !sessionStorage.getItem("uidType" || !sessionStorage.getItem("socketUrl"))
//     ) {
//       alert("非法访问，请登陆");
//       window.location.href = "#/";
//     }
//   },
  mounted() {
    // 创建worker
    this.wroker = new Worker("../../static/js/ludan2.js");
    this.wroker.onmessage = data => {
      let msg = data.data;
      this.$refs.screen[msg.room].$refs.ld.setLudan(msg);
    };
    if (this.loadingStore >= 100) {
        // 获取列表信息
        let UId = this.$store.getters.userMsg.UId;
        let RandCode = this.$store.getters.userMsg.RandCode;
        let GT = this.$store.getters.userMsg.GT;
        let msg = JSON.stringify({
          ActType: 3,
          ConnectionId: "",
          Content: { HallNumber: this.index + 1 },
          ErrorCode: 10000,
          RandCode,
          UId,
          GT
        });
        window.Socket.uSend(msg);
    }
  },
  // 销毁
  beforeDestroy() {
    this.wroker.terminate();
    this.wroker = null;
  }

}
</script>


<style>
*{
    margin: 0;
    padding: 0;
}
html,body{
	width: 100%;
	height: 100%;
	background: url();
	/*background: #fff;*/
	min-width: 1028px;
	overflow: auto;
}
.gameTable{
	overflow: hidden;
	width: 100%;
	height: 100%; 
   
}
</style>
